unit sysstting;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, drawQC, Grids, RzGrids;

type
  Tsyssttingfrm = class(TForm)
    pal_ctrl: TPanel;
    btnClose: TSpeedButton;
    labcaption: TLabel;
    palbg: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    txtcmpyname: TEdit;
    txtsftname: TEdit;
    txtextdinfo1: TEdit;
    txtextdinfo2: TEdit;
    txtextdinfo3: TEdit;
    txtextdinfo4: TEdit;
    txtextdinfo5: TEdit;
    txtextdinfo6: TEdit;
    Label11: TLabel;
    Label12: TLabel;
    comRFIDLen: TComboBox;
    comDateFmt: TComboBox;
    Label13: TLabel;
    Label14: TLabel;
    comPayday: TComboBox;
    chkshgross: TCheckBox;
    chkshgqf: TCheckBox;
    chkshpenlty: TCheckBox;
    chkremvmem: TCheckBox;
    txtmquee: TMemo;
    Label15: TLabel;
    taxGrid: TStringGrid;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Label16: TLabel;
    Label17: TLabel;
    txtNoTFNrate: TEdit;
    Label18: TLabel;
    RFID100: TCheckBox;
    procedure pal_ctrlResize(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure taxGridDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure SpeedButton2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure taxGridKeyPress(Sender: TObject; var Key: Char);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  syssttingfrm: Tsyssttingfrm;

implementation

{$R *.dfm}

uses
  includefile, main;

procedure Tsyssttingfrm.pal_ctrlResize(Sender: TObject);
begin
  btnClose.Left:=pal_ctrl.Width-btnClose.Width-3;
end;

procedure Tsyssttingfrm.btnCloseClick(Sender: TObject);
begin
  Hide;
end;

procedure Tsyssttingfrm.FormResize(Sender: TObject);
begin
  palbg.Left:=(Width-palbg.Width) div 2;
  palbg.top:=(Height-palbg.Height)div 2;
end;

procedure Tsyssttingfrm.taxGridDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  vCol, vRow : LongInt;
  tW,tH:LongInt;
begin
  vCol := ACol; vRow := ARow;
  With Sender as TStringGrid, Canvas do begin
    tW:=(Rect.Right-Rect.Left-TextWidth(Cells[vCol, vRow])) div 2;
    tH:=(Rect.Bottom-Rect.Top-TextHeight('A')) div 2;
    FillRect(Rect);
    if vRow=0 then begin
      Font.Style :=Font.Style+[fsBold];
      //TextRect(Rect, Rect.Left+tW, Rect.Top+tH, Cells[vCol, vRow]);
    end else begin
      Font.Style :=Font.Style-[fsBold];
    end;
    TextRect(Rect, Rect.Left+tW, Rect.Top+tH, Cells[vCol, vRow]);
  end;

end;

procedure Tsyssttingfrm.SpeedButton2Click(Sender: TObject);
begin
  Hide;
end;

procedure Tsyssttingfrm.FormCreate(Sender: TObject);
var
  I:integer;
  tmp:string;
begin
  for I:=0 to ComponentCount-1 do begin
    if Components[I] is TLabel then begin
      if 0<>TLabel(Components[I]).Tag then
        TLabel(Components[I]).Caption:=
                GetCaption(name,TLabel(Components[I]).Tag);
    end;
    if Components[I] is TSpeedButton then begin
      if 0<>TSpeedButton(Components[I]).Tag then
        TSpeedButton(Components[I]).Caption:=
                GetCaption(name,TSpeedButton(Components[I]).Tag);
    end;
    if Components[I] is TCheckBox then begin
      if 0<>TCheckBox(Components[I]).Tag then
        TCheckBox(Components[I]).Caption:=
                GetCaption(name,TCheckBox(Components[I]).Tag);
    end;
  end;
  with taxGrid do begin
    Cells[0,0]:='From($)';
    Cells[1,0]:='To($)';
    Cells[2,0]:='Fix($)';
    Cells[3,0]:='Rate(%)';
    RowCount:=MAXTFNTAXCOUNT+1;
    for I:=1 to MAXTFNTAXCOUNT do begin
      Cells[0,I]:=InttoStr(TFNTaxLevel[I-1].taxfrom);
      Cells[1,I]:=InttoStr(TFNTaxLevel[I-1].taxto);
      Cells[2,I]:=InttoStr(TFNTaxLevel[I-1].taxfix);
      Cells[3,I]:=InttoStr(TFNTaxLevel[I-1].taxrate);
    end;
  end;
  with inif do begin
    txtcmpyname.Text:=ReadString('system','companyname','');
    txtsftname.Text:=ReadString('system','software','');
    txtextdinfo1.Text:=ReadString('system','ExtendInfo1','');
    txtextdinfo2.Text:=ReadString('system','ExtendInfo2','');
    txtextdinfo3.Text:=ReadString('system','ExtendInfo3','');
    txtextdinfo4.Text:=ReadString('system','ExtendInfo4','');
    txtextdinfo5.Text:=ReadString('system','ExtendInfo5','');
    txtextdinfo6.Text:=ReadString('system','ExtendInfo6','');
    txtmquee.Text:=ReadString('system','marquee','');
    comRFIDLen.ItemIndex:=Readinteger('system','RFIDLen',5)-1;
    txtNoTFNrate.Text:=Readstring('system','NoTFNtax','45');
    tmp:=ReadString('system','DateFrtStr','dd/MM/yyyy');
    if 'dd/MM/yyyy'=tmp then
      comDateFmt.ItemIndex:=0
    else if 'MM/dd/yyyy'=tmp  then
      comDateFmt.ItemIndex:=1
    else
      comDateFmt.ItemIndex:=2;
    comPayday.ItemIndex:=Readinteger('system','PayDay',0);
    case ReadInteger('system','IsAllowRFID100',1) of
      1:RFID100.Checked:=True;
      else RFID100.Checked:=False;
    end;
    case ReadInteger('system','showGQF',1) of
      1:chkshgqf.Checked:=True;
      else chkshgqf.Checked:=False;
    end;
    case ReadInteger('system','showPenalty',1) of
      1: chkshpenlty.Checked:=True;
      else chkshpenlty.Checked:=False;
    end;
    case ReadInteger('system','showGW',1) of
      1: chkshgross.Checked:=True;
      else chkshgross.Checked:=False;
    end;
    case ReadInteger('system','IsRemoveMen',0) of
      1: chkremvmem.Checked:=True;
      else chkremvmem.Checked:=False;
    end;
  end;
end;

procedure Tsyssttingfrm.taxGridKeyPress(Sender: TObject; var Key: Char);
begin
  case key of
    '0'..'9',#$08,'.':begin  end;
    else begin
      key:=#00;
      Application.MessageBox(pchar(GetCaption('MsgBox',111)),
                             pchar(GetCaption('MsgBox',106)),MB_ICONINFORMATION);
    end;
  end;
end;

procedure Tsyssttingfrm.SpeedButton1Click(Sender: TObject);
var
  i,code,tmp:integer;
begin
  with inif do begin
    WriteString('system','companyname',txtcmpyname.Text);
    WriteString('system','software',txtsftname.Text);
    WriteString('system','ExtendInfo1',txtextdinfo1.Text);
    WriteString('system','ExtendInfo2',txtextdinfo2.Text);
    WriteString('system','ExtendInfo3',txtextdinfo3.Text);
    WriteString('system','ExtendInfo4',txtextdinfo4.Text);
    WriteString('system','ExtendInfo5',txtextdinfo5.Text);
    WriteString('system','ExtendInfo6',txtextdinfo6.Text);
    WriteString('system','marquee',txtmquee.Text);
    Writeinteger('system','RFIDLen',comRFIDLen.ItemIndex+1);
    Writeinteger('system','PayDay',comPayday.ItemIndex);
    val(txtNoTFNrate.Text,tmp,code);
    Writeinteger('system','NoTFNtax',tmp);
    mainfrm.SetInfo([
             txtcmpyname.Text,
             txtmquee.Text,
             txtsftname.Text,
             txtextdinfo1.Text,
             txtextdinfo2.Text,
             txtextdinfo3.Text,
             txtextdinfo4.Text,
             txtextdinfo5.Text,
             txtextdinfo6.Text
            ]);

    case comDateFmt.ItemIndex of
      0:WriteString('system','DateFrtStr','dd/MM/yyyy');
      1:WriteString('system','DateFrtStr','MM/dd/yyyy');
      2:WriteString('system','DateFrtStr','yyyy/MM/dd');
    end;
    if chkshgqf.Checked then
      WriteInteger('system','showGQF',1)
    else
      WriteInteger('system','showGQF',0);
    if chkshpenlty.Checked then
      WriteInteger('system','showPenalty',1)
    else
      WriteInteger('system','showPenalty',0);
    if chkshgross.Checked then
      WriteInteger('system','showGW',1)
    else
      WriteInteger('system','showGW',0);
    if chkremvmem.Checked then
      WriteInteger('system','IsRemoveMen',1)
    else
      WriteInteger('system','IsRemoveMen',0);
    if RFID100.Checked then
      WriteInteger('system','IsAllowRFID100',1)
    else
      WriteInteger('system','IsAllowRFID100',0);

    for i:=1 to MAXTFNTAXCOUNT do begin
      val(taxGrid.Cells[0,i],TFNTaxLevel[I-1].taxfrom,code);
      writeInteger('system','taxfrom'+Trim(inttostr(I)),TFNTaxLevel[I-1].taxfrom);
      val(taxGrid.Cells[1,i],TFNTaxLevel[I-1].taxto,code);
      writeInteger('system','taxto'+Trim(inttostr(I)),TFNTaxLevel[I-1].taxto);
      val(taxGrid.Cells[2,i],TFNTaxLevel[I-1].taxfix,code);
      writeInteger('system','taxfix'+Trim(inttostr(I)),TFNTaxLevel[I-1].taxfix);
      val(taxGrid.Cells[3,i],TFNTaxLevel[I-1].taxrate,code);
      writeInteger('system','taxrate'+Trim(inttostr(I)),TFNTaxLevel[I-1].taxrate);
    end;
  end;
  iniSystemParma;
  case Application.MessageBox(pchar(GetCaption('Msgbox',112)),
                              pchar(GetCaption('Msgbox',113)),
                              64) of 
    1..7:Hide;
  end;
end;

end.
